<link rel="stylesheet" type="text/css" href="__STATIC__/admin_page/static/h-ui/css/H-ui.min.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/admin_page/static/h-ui.admin/css/H-ui.admin.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/admin_page/lib/Hui-iconfont/1.0.8/iconfont.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/admin_page/static/h-ui.admin/skin/default/skin.css" id="skin"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/admin_page/static/h-ui.admin/css/style.css"/>
<script type="text/javascript" src="/static/js/vue2.5.1.js"></script>
<script src="/static/js/axios.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin_page/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin_page/lib/layer/2.4/layer.js"></script>
<script src="/static/js/jquery.base64.js"></script>
<article class="page-container" id="app">
    <form class="form form-horizontal" id="form-article-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>公司名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" v-model="company_name" value=""
                       name="company_name">

            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>公司名称(英文)：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" v-model="company_name_us" value=""
                       name="company_name_us">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>服务号名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" v-model="service_name" value=""
                       name="service_name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>服务号名称(英文)：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" v-model="service_name_en" value=""
                       name="service_name_en">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>服务类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                {foreach $data['service_all_types'] as $vo}
                {in name="$vo['service_type_id']" value="$data['service_types']"}
                <label class="">
                    <input type="checkbox" value="{$vo['service_type_id']}" checked="checked"
                           name="service_type_name">
                    {$vo['service_type_name']}</label>
                {else/} <label class="">
                <input type="checkbox" value="{$vo['service_type_id']}" name="service_type_name">
                {$vo['service_type_name']}</label>
                {/in}
                {/foreach}
            </div>
        </div>
        <input type="hidden" name="service_id" value="{$data['service_id']}">
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <div @click="save_submit" class="btn btn-primary radius"><i
                        class="Hui-iconfont">&#xe632;</i> 保存
                </div>
            </div>
        </div>
    </form>
</article>
<script>
    new Vue({
        el: '#app',
        data: {
            company_name: "{$data['company_name']}",
            company_name_us: "{$data['company_name_us']}",
            service_name_en: "{$data['service_name_en']}",
            service_name: "{$data['service_name']}",
            service_id: "{$data['service_id']}",
            service_type_ids: '',
        },
        created() {

        },
        methods: {
            save_submit() {
                obj = document.getElementsByName("service_type_name");
                check_val = [];
                for (k in obj) {
                    if (obj[k].checked)
                        check_val.push(obj[k].value);
                }
                if (check_val.length == 0) {
                    layer.alert('服务类不能为空');
                    return false;
                }
                if (check_val.length > 5) {
                    layer.alert('服务类不能大于5个')
                    return false;
                }
                this.service_type_ids = JSON.stringify(check_val);
                axios.post('/admin/Service/editServiceInfo',
                    {
                        company_name: this.company_name,
                        company_name_us: this.company_name_us,
                        service_type_ids: this.service_type_ids,
                        request_type: 'h5',
                        service_id: this.service_id,
                        service_name: this.service_name,
                        service_name_en: this.service_name_en,
                    }
                ).then(response => {
                    console.log('===========================')
                    if (response.data.status == 200) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    } else {
                        layer.alert(response.data.msg)
                    }
                })
            }
        }
    })
</script>